#ifndef Mutex_h__
#define Mutex_h__

#include <SDL.h>

class Mutex
{
private:
    Mutex(const Mutex&);
    Mutex& operator=(const Mutex&);
public:
    Mutex()
    { 
        m_mutex =  SDL_CreateMutex();
    }

    ~Mutex()
    {
        SDL_DestroyMutex(m_mutex);
    }


    void Lock()
    { 
        SDL_LockMutex(m_mutex);
    }

    void Unlock()
    { 
        SDL_UnlockMutex(m_mutex);
    }

protected:
    // the critical section itself
    mutable SDL_mutex* m_mutex;
};

class ScopedMutexLock
{
private:
    ScopedMutexLock(ScopedMutexLock&);
    ScopedMutexLock& operator=(ScopedMutexLock&);
public:
    ScopedMutexLock( Mutex & csResource)
        : m_csResource( csResource)
    {
        m_csResource.Lock();
    }

    ~ScopedMutexLock()
    {
        m_csResource.Unlock();
    }

private:
    // the Critical Section for this resource
    Mutex & m_csResource;
};

#endif // Mutex_h__